package com.cyurs.netty.nettySimple.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.charset.Charset;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/11/23
 */
public class NettyByteBuf1 {
    public static void main(String[] args) {
        ByteBuf byteBuf = Unpooled.copiedBuffer("hello,wor  ld!", Charset.forName("utf-8"));

        if (byteBuf.hasArray()) {
            byte[] content = byteBuf.array();

            System.out.println(new String(content, Charset.forName("utf-8")));
            System.out.println(byteBuf.capacity());
            System.out.println(byteBuf.arrayOffset());
            System.out.println(byteBuf.readerIndex());
            System.out.println(byteBuf.writerIndex());
            System.out.println(byteBuf.capacity());
            System.out.println(byteBuf.readableBytes());

            System.out.println(byteBuf.getCharSequence(1, 5, Charset.forName("utf-8")));

        }
    }
}
